import GameView from "../../../../quick/core/ui/GameView";
import StateMachineBoy from "./StateMachineBoy";
import { doStateMachine } from "./StateMachineTest";

/**
 * @description StateMachineGameView
 */
const {ccclass, property} = cc._decorator;

@ccclass
export default class StateMachineGameView extends GameView {
    public static getPrefabUrl() {
        return "prefabs/StateMachineGameView";
    }

    private boy : StateMachineBoy = null;

    onLoad(): void {
        super.onLoad();
        this.onN(cc.find("goback",this.node),cc.Node.EventType.TOUCH_END,this.backBundle);
        this.boy = cc.find("Boy",this.node)?.addComponent(StateMachineBoy);
        // doStateMachine();
        let op = cc.find("op",this.node);
        if ( op ){
            Object.values(StateMachineBoy.State).forEach(v=>{
                this.onN(cc.find(v,op),cc.Node.EventType.TOUCH_END,()=>{
                    this.boy.onChangeState(v);
                })
            })
            this.onN(cc.find(this.boy.shoot,op),cc.Node.EventType.TOUCH_END,()=>{
                this.boy.onShoot();
            });
            this.onN(cc.find("debugSlots",op),cc.Node.EventType.TOUCH_END,()=>{
                this.boy.onDebugSlots();
            });
            this.onN(cc.find("debugBones",op),cc.Node.EventType.TOUCH_END,()=>{
                this.boy.onDebugBones();
            });
            this.onN(cc.find("timeScale",op),cc.Node.EventType.TOUCH_END,()=>{
                this.boy.onTimeScale();
            });
            this.onN(cc.find("step",op),cc.Node.EventType.TOUCH_END,()=>{
                this.boy.onStep();
            })
        }

        doStateMachine();
    }
}
